﻿using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

namespace TowerDefence_Zombie
{
    public class UIGuide : UGuiFormEx
    {
        [SerializeField] private Transform fingerTrans;
        [SerializeField] private Transform hintTrans;
        [SerializeField] private TMP_Text hintText;
        [SerializeField] private RectGuide rectGuide;

        public void SetFingerPosition(Vector3 fingerPos, bool isPlayDragAnim = false, Vector3 dragTarPos = new())
        {
            SetFingerActiveState(true);
            fingerTrans.position = fingerPos;
            if (isPlayDragAnim)
            {
                fingerTrans.DOMove(dragTarPos, 1.2f)
                    .SetEase(Ease.Linear)
                    .SetLoops(-1, LoopType.Yoyo);
            }
            else
            {
                var localTweenPos = fingerTrans.localPosition;
                localTweenPos.x -= 20;
                localTweenPos.y -= 20;
                fingerTrans.DOLocalMove(localTweenPos, 1.0f)
                    .SetEase(Ease.Linear)
                    .SetLoops(-1, LoopType.Yoyo);
            }
        }

        public void SetHintTextInfo(string hintStr)
        {
            SetHintActiveState(true);
            hintText.text = LanguageManager.GetLocalizedString(hintStr);
            //hintTrans.position = hintPos;
        }

        public void ProcessMarkArea(RectTransform maskAreaTrans)
        {
            SetMaskActiveState(true);
            rectGuide.Guide(maskAreaTrans);
        }

        public void SetFingerActiveState(bool state)
        {
            fingerTrans?.DOKill();
            fingerTrans.gameObject.SetActive(state);
        }

        public void SetHintActiveState(bool state)
        {
            hintTrans.gameObject.SetActive(state);
        }

        public void SetMaskActiveState(bool state)
        {
            rectGuide.gameObject.SetActive(state);
        }
    }
}
